/****************************************************************************
File:			EDFrustum.h
Purpose:		The declaration of our EDFrustum class that will be updated
				every frame and help us cull objects from rendering by testing
				their bounding volume against the frustum. Several of the
				functions declared in the class will be defined in 
				"ED1FrustumTODOS.cpp" by the ED1 Students.
Author:			Matt Norris [mnorris@fullsail.com]
School:			Full Sail University
Last Modified:	July 1st, 2009
*****************************************************************************/

#ifndef _EDFRUSTUM_H_
#define _EDFRUSTUM_H_

#include "matrix4.h"
#include "EDAABB.h"
#include "EDSphere.h"

class EDFrustum
{
	enum{ ntl = 0, ntr, nbr, nbl, ftl, ftr, fbr, fbl };

	vec3f m_points[8];

	const matrix4f *m_pMatrix;

	float m_fRatio;
	float m_fNear;
	float m_fFar;
	float m_fFOV;

	float m_HNear;
	float m_HFar;

	float m_WNear;
	float m_WFar;

	enum{ PNEAR = 0, PFAR, PLEFT, PRIGHT, PTOP, PBOTTOM };

	vec3f m_Normals[6];
	float m_Distances[6];

public:

	EDFrustum(void){}
	virtual ~EDFrustum(){}

	void Set( const matrix4f *pMatrix, float fRatio, float fNear, float fFar, float fFOV );

	void Update(void);

	void Render(void);

	// GetPlaneEquation
	//
	// Calculates the values of a plane from three points on the plane
	//
	// In:
	//		vec3f &Normal - Where to store the normal of the plane
	//		float &Distance - Where to store the distance to the plane
	//		const vec3f &Point1 - The first point on the plane
	//		const vec3f &Point2 - The second point on the plane
	//		const vec3f &Point3 - The third point on the plane
	//
	// Out:
	//		vec3f &Normal - The normal of the plane
	//		float &Distance - The distance to the plane
	//
	// Remarks:
	//		Once this function is complete, the normals of the frustum will become visible when it is rendered.
	friend void GetPlaneEquation( vec3f &Normal, float &Distance, const vec3f &Point1, const vec3f &Point2, const vec3f &Point3 );

	// TestAABB
	// 
	// Performs a collision test with the frustum and an Axis-Aligned Bounding Box (AABB)
	//
	// In:
	//		EDAABB& box - The AABB to test collision with
	//
	// Return:
	//		bool - True if there was collision. False if there was not.
	bool TestAABB( EDAABB& box );

	// TestSphere
	// 
	// Performs a collision test with the frustum and an bounding sphere
	//
	// In:
	//		EDSphere& sphere - The sphere to test collision with
	//
	// Return:
	//		bool - True if there was collision. False if there was not.
	bool TestSphere( EDSphere& sphere );
};

#endif